import 'animate.css'; // 动画库
import Vue from 'vue';
import Vuex from 'vuex';
import ElementUI from 'element-ui';
import VueRouter from 'vue-router';
import CommonDirective from 'common-directive'; // 通用指令
import CommonComponent from 'common-component'; // 通用组件
import VueHtml5Editor from 'vue-html5-editor';
import 'font-awesome/css/font-awesome.min.css';

import './assets/reset.css';
import './javascript.common';
import './axios.config';
import Login from './components/Login';
import VuexConfig from './vuex.config';
import RouterConfig from './router.config';
import ComponentConfig from './component.config';
import VueEditorConfig from './vueeditor.config';

// 添加依赖
Vue.use(Vuex);
Vue.use(VueRouter);
Vue.use(ElementUI);
Vue.use(CommonDirective, {
  point: {
    http: Vue.prototype.$http,
    url: '/api/start/verify',
    debug: true,
  },
}); // 使用通用指令(埋点配置)
Vue.use(CommonComponent); // 使用通用组件
Vue.use(VueHtml5Editor, VueEditorConfig.options);

// 配置全局组件
ComponentConfig.components.forEach(item => {
  Vue.component(item.key, item.value);
});

// 路由初始化及实例化
RouterConfig.init()
  .then(routes => {
    new Vue({
      el: '#backendApp',
      router: new VueRouter({
        mode: 'history',
        routes,
      }),
      store: new Vuex.Store({
        state: VuexConfig.state,
        mutations: VuexConfig.mutations,
      }),
      mounted() {
        console.log(
          '%c vue-base-demo %c 手摸手，教你用vue搭建最小管理系统 %c',
          'background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px;  color: #fff',
          'background:#41b883 ; padding: 1px; border-radius: 0 3px 3px 0;  color: #fff',
          'background:transparent;'
        );
        document.dispatchEvent(new Event('render-event')); // 预渲染
      },
    });
  })
  .catch(() => {
    new Vue({
      el: '#backendApp',
      router: new VueRouter({
        mode: 'history',
        routes: [{ path: '/', component: Login }, { path: '*', redirect: '/' }],
      }),
      mounted() {
        document.dispatchEvent(new Event('render-event')); // 预渲染
      },
    });
  });
// alert('升级http参数类型');
